import { Component, OnInit } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { HttpRequest } from "../../../../service/httpRequest";
import { NotiService } from "../../../../service/noti.service";

declare let require:any;
let Base64 = require('../../../../../assets/js/Base64');
declare let $:any;
@Component({
  selector: 'app-single-monitor-multi',
  templateUrl: './single-monitor-multi.component.html',
  styleUrls: [
    '../../../../../assets/css/convertor-v1.1.css',
    '../../../../../assets/css/hzw-city-picker.css',
    './single-monitor-multi.component.css',
  ]
})
export class SingleMonitorMultiComponent implements OnInit {

  deviceId:string = '';
  chart1:any;
  chart2:any;
  chart3:any;
  chart4:any;
  chart5:any;
  chart6:any;
  chart7:any;
  chart8:any;
  chart9:any;
  chart10:any;
  private gizwitsNotiWs:any;
  private eventType = ['device.status.kv','device.status.raw'];

  //show hide
  bpqsm2:boolean = false;
  bpqfg:boolean = false;


  constructor(private activeRoute:ActivatedRoute,private httpRequest:HttpRequest,private noti:NotiService) { }

  ngOnInit() {
    this.activeRoute.params.subscribe(
      params=>{
        this.deviceId = params['deviceId'].replace('|','/');

        let p = this.deviceId.split('/');
        this.gizwitsNotiWs = this.noti.init(p[0].toLocaleLowerCase(),[p[1]],this.eventType,this.onEvent,this);
        this.gizwitsNotiWs.connect();
        this.initChart();
      }
    );
  }

  change(i){
    let cboxs = $('.xx-box');
    if(i >= cboxs.length) return ;
    $.each(cboxs,function(j,n){
      $(n).hide();
      $('.nav-title').eq(j).removeClass('active')
    });
    $('.xx-box').eq(i).show();
    $('.nav-title').eq(i).addClass('active');
  }

  bianpinqi(){
    let p = this.deviceId.split('/');
    this.httpRequest.sendPost('common/sendCommand',{
      product_id:p[0],
      mac:p[1],
      command:"{\"attrs\":{\"cmd\":\"bianpinqi\"}}"
    }).subscribe(	res => console.log(res),err =>{})
  }

  getfault(){
    let p = this.deviceId.split('/');
    this.httpRequest.sendPost('common/sendCommand',{
      product_id:p[0],
      mac:p[1],
      command:"{\"attrs\":{\"cmd\":\"func_fault\"}}"
    }).subscribe(	res => console.log(res),err =>{})
  }

  initChart(){
    let plotBands;
    plotBands = [
      {from: -90, to: -60, color: '#DF5353' },
      {from: -60, to: -30, color: '#DDDF0D' },
      {from: -30, to: 30, color: '#55BF3B' },
      { from:30,to: 60,color: '#DDDF0D'},
      {from: 60,to: 90,color: '#DF5353'}];
    this.init('qssd','目标速度',-150,150,-90,90,'速度',0.0,'Hz',plotBands,(chart)=>{
      this.chart1 = chart;
    });

    plotBands = [
      {from: 0, to: 40, color: '#55BF3B' },
      { from: 40,to:80 ,color: '#DDDF0D'},
      {from: 80,to: 120,color: '#DF5353'}];
    this.init('qsdl','输出电流',-150,150,0,120,'电流',0.0,'A',plotBands,(chart)=>{
      this.chart2 = chart;
    });

    plotBands = [
      {from: -90, to: -60, color: '#DF5353' },
      {from: -60, to: -30, color: '#DDDF0D' },
      {from: -30, to: 30, color: '#55BF3B' },
      { from:30,to: 60,color: '#DDDF0D'},
      {from: 60,to: 90,color: '#DF5353'}];
    this.init('qssdf','目标速度',-150,150,-90,90,'速度',0.0,'Hz',plotBands,(chart)=>{
      this.chart3 = chart;
    });

    plotBands = [
      {from: 0, to: 40, color: '#55BF3B' },
      { from: 40,to:80 ,color: '#DDDF0D'},
      {from: 80,to: 120,color: '#DF5353'}];
    this.init('qsdlf','输出电流',-150,150,0,120,'电流',0.0,'A',plotBands,(chart)=>{
      this.chart4 = chart;
    });

    plotBands = [
      {from: -90, to: -60, color: '#DF5353' },
      {from: -60, to: -30, color: '#DDDF0D' },
      {from: -30, to: 30, color: '#55BF3B' },
      { from:30,to: 60,color: '#DDDF0D'},
      {from: 60,to: 90,color: '#DF5353'}];
    this.init('xcsd','目标速度',-150,150,-90,90,'速度',0.0,'Hz',plotBands,(chart)=>{
      this.chart5 = chart;
    });

    plotBands = [
      {from: 0, to: 40, color: '#55BF3B' },
      { from: 40,to:80 ,color: '#DDDF0D'},
      {from: 80,to: 120,color: '#DF5353'}];
    this.init('xcdl','输出电流',-150,150,0,120,'电流',0.0,'A',plotBands,(chart)=>{
      this.chart6 = chart;
    });
    plotBands = [
      {from: -90, to: -60, color: '#DF5353' },
      {from: -60, to: -30, color: '#DDDF0D' },
      {from: -30, to: 30, color: '#55BF3B' },
      { from:30,to: 60,color: '#DDDF0D'},
      {from: 60,to: 90,color: '#DF5353'}];
    this.init('xc2sd','目标速度',-150,150,-90,90,'速度',0.0,'Hz',plotBands,(chart)=>{
      this.chart7 = chart;
    });

    plotBands = [
      {from: 0, to: 40, color: '#55BF3B' },
      { from: 40,to:80 ,color: '#DDDF0D'},
      {from: 80,to: 120,color: '#DF5353'}];
    this.init('xc2dl','输出电流',-150,150,0,120,'电流',0.0,'A',plotBands,(chart)=>{
      this.chart8 = chart;
    });
    plotBands = [
      {from: -90, to: -60, color: '#DF5353' },
      {from: -60, to: -30, color: '#DDDF0D' },
      {from: -30, to: 30, color: '#55BF3B' },
      { from:30,to: 60,color: '#DDDF0D'},
      {from: 60,to: 90,color: '#DF5353'}];
    this.init('dcsd','目标速度',-150,150,-90,90,'速度',0.0,'Hz',plotBands,(chart)=>{
      this.chart9 = chart;
    });

    plotBands = [
      {from: 0, to: 40, color: '#55BF3B' },
      { from: 40,to:80 ,color: '#DDDF0D'},
      {from: 80,to: 120,color: '#DF5353'}];
    this.init('dcdl','输出电流',-150,150,0,120,'电流',0.0,'A',plotBands,(chart)=>{
      this.chart10 = chart;
    });
  }




  updatechart(chart,data){
    if (!chart.renderer.forExport) {
      let point = chart.series[0].points[0];
      point.update(data);
    }
  }

  init(id,text,startAg,endAg,min,max,name,initVal,subfix,pb,cb) {
    let windowwith = (($(document.body).width()) * 7 / 12 - 10) / 2 - 30;
    $('#' + id).highcharts({
        chart: {
          type: 'gauge',
          plotBackgroundColor: null,
          plotBackgroundImage: null,
          plotBorderWidth: 0,
          plotShadow: false,
          width: windowwith
        },
        title: {
          text: ''

        },
        pane: {
          startAngle: startAg,
          endAngle: endAg,
          center: ['50%', '50%'],
          background: [{
            backgroundColor: {
              linearGradient: {x1: 0, y1: 0, x2: 0, y2: 1},
              stops: [
                [0, '#FFF'],
                [1, '#333']
              ]
            },
            borderWidth: 0,
            outerRadius: '109%'
          }, {
            backgroundColor: {
              linearGradient: {x1: 0, y1: 0, x2: 0, y2: 1},
              stops: [
                [0, '#333'],
                [1, '#FFF']
              ]
            },
            borderWidth: 1,
            outerRadius: '107%'
          }, {}, {
            backgroundColor: '#DDD',
            borderWidth: 0,
            outerRadius: '105%',
            innerRadius: '103%'
          }]
        },

        yAxis: {
          min: min,
          max: max,
          minorTickInterval: 'auto',
          minorTickWidth: 1,
          minorTickLength: 10,
          minorTickPosition: 'inside',
          minorTickColor: '#666',
          tickPixelInterval: 30,
          tickWidth: 2,
          tickPosition: 'inside',
          tickLength: 10,
          tickColor: '#666',
          labels: {
            step: 2,
            rotation: 'auto'
          },
          title: {
            text: subfix
          },
          plotBands: pb
        },

        series: [{
          name: name,
          data: [initVal],
          tooltip: {
            valueSuffix: ' ' + subfix + ' '
          }
        }]

      },
      function (chart) {
        cb(chart);
      });
  }

  onEvent(msg,that){
    if(msg.event_type=="device_status_raw"){
      //console.log(msg.data.raw);
      let tdata = Base64.Base64.decode(msg.data.raw.replace(/[\n]/ig,''));
      //console.log(tdata);
      let zdata = JSON.parse(tdata);
      for(let key in zdata){

        if(parseInt(msg[key])==msg[key]){
          $("#"+key).text(Number(msg[key]));
        }else{
          $("#"+key).text(Number(msg[key]).toFixed(2));
        }

        $("#"+key).text(zdata[key]);
        if(zdata[key]=="0" && $("#"+key).attr("tag")=="jg")
        {
          $("#"+key).text("停止");
        }
        if(zdata[key]=="1" && $("#"+key).attr("tag")=="jg")
        {
          $("#"+key).text("低速正转");
        }
        if(zdata[key]=="2" && $("#"+key).attr("tag")=="jg")
        {
          $("#"+key).text("高速正转");
        }
        if(zdata[key]=="3" && $("#"+key).attr("tag")=="jg")
        {
          $("#"+key).text("低速反转");
        }
        if(zdata[key]=="4" && $("#"+key).attr("tag")=="jg")
        {
          $("#"+key).text("高速反转");
        }
        if(zdata[key]=="5" && $("#"+key).attr("tag")=="jg")
        {
          $("#"+key).text("停止中");
        }

        if(zdata[key]=="0" && $("#"+key).attr("tag")=="qskz")
        {
          $("#"+key).text("双速电机");
        }

        if(zdata[key]=="1" && $("#"+key).attr("tag")=="qskz")
        {
          $("#"+key).text("端子");
        }

        if(zdata[key]=="2" && $("#"+key).attr("tag")=="qskz")
        {
          $("#"+key).text("Modbus");
        }

        if(zdata[key]=="0" && $("#"+key).attr("tag")=="smt")
        {
          $("#"+key).text("停止");
        }
        if(zdata[key]=="1" && $("#"+key).attr("tag")=="smt")
        {
          $("#"+key).text("停止中");
        }

        if(zdata[key]=="2" && $("#"+key).attr("tag")=="smt")
        {
          $("#"+key).text("低速正转");
        }
        if(zdata[key]=="3" && $("#"+key).attr("tag")=="smt")
        {
          $("#"+key).text("低速反转");
        }
        if(zdata[key]=="4" && $("#"+key).attr("tag")=="smt")
        {
          $("#"+key).text("高速正转");
        }
        if(zdata[key]=="5" && $("#"+key).attr("tag")=="smt")
        {
          $("#"+key).text("高速反转");
        }

        if(zdata[key]=="0" && $("#"+key).attr("tag")=="sr"){

          $("#"+key).text( "X" + key.substr(key.length-2));
          $("#"+key).removeClass("green");
          $("#"+key).addClass("gray");
        }

        if(zdata[key]=="1" && $("#"+key).attr("tag")=="sr")
        {
          $("#"+key).text( "X" + key.substr(key.length-2));
          $("#"+key).removeClass("gray");
          $("#"+key).addClass("green");
        }

        if(zdata[key]=="0" && $("#"+key).attr("tag")=="sc")
        {
          $("#"+key).text( "K" + key.substr(key.length-1));
          $("#"+key).removeClass("blue");
          $("#"+key).addClass("gray");

        }

        if(zdata[key]=="1" && $("#"+key).attr("tag")=="sc")
        {
          $("#"+key).text( "K" + key.substr(key.length-1));
          $("#"+key).removeClass("gray");
          $("#"+key).addClass("blue");

        }

        if(zdata[key]=="0" && $("#"+key).attr("tag")=="sc1")
        {
          $("#"+key).text( "Y" + key.substr(key.length-2));
          $("#"+key).removeClass("blue");
          $("#"+key).addClass("gray");

        }

        if(zdata[key]=="1" && $("#"+key).attr("tag")=="sc1")
        {
          $("#"+key).text( "Y" + key.substr(key.length-2));
          $("#"+key).removeClass("gray");
          $("#"+key).addClass("blue");

        }

        if(zdata[key]=="0" && $("#"+key).attr("tag")=="srbp")
        {
          //console.log(zdata[key]);
          $("#"+key).text( "X" + key.substr(key.length-1));
          $("#"+key).removeClass("green");
          $("#"+key).addClass("gray");
        }

        if(zdata[key]=="1" && $("#"+key).attr("tag")=="srbp")
        {
          $("#"+key).text( "X" + key.substr(key.length-1));
          $("#"+key).removeClass("gray");
          $("#"+key).addClass("green");
        }

        if(zdata[key]=="0" && $("#"+key).attr("tag")=="scbp")
        {
          $("#"+key).text( "Y" + key.substr(key.length-1));
          $("#"+key).removeClass("blue");
          $("#"+key).addClass("gray");
        }

        if(zdata[key]=="1" && $("#"+key).attr("tag")=="scbp")
        {
          $("#"+key).text( "Y" + key.substr(key.length-1));
          $("#"+key).removeClass("gray");
          $("#"+key).addClass("blue");
        }

      }
    }
    if(msg.event_type=="device_status_kv"){
      msg = msg.data;
      //console.log(msg);

      if (msg.main_ctrlmode=="0") {
        let dd = msg.main_givfrq.toFixed(1);
        that.updatechart(that.chart1,parseFloat(dd));
        let a = msg.main_motorcur.toFixed(1);
            that.updatechart(that.chart2,parseFloat(a));
        let hh = msg.vice_givfrq.toFixed(1);
        that.updatechart(that.chart3,parseFloat(hh));
        let i = msg.vice_motorcur.toFixed(1);
        that.updatechart(that.chart4,parseFloat(i));
      }
      if(msg.main_ctrlmode=="1"||msg.main_ctrlmode=="2"){
        // let a = msg.main_motorcur.toFixed(1);
        // updatechart(chart1,parseFloat(a));
      }

      let mlidiheight = msg.main_height;
      that.mmovePointer(mlidiheight);
      let vlidiheight = msg.vice_height;
      that.vmovePointer(vlidiheight);
      let xcxingcheng = msg.small1_position;
      that.xmovePointer(xcxingcheng);
      let xcxingcheng2 = msg.small2_position;
      that.x2movePointer(xcxingcheng2);
      let dcxingcheng = msg.large_position;
      that.dmovePointer(dcxingcheng);

      // let b = msg.small2_givfrq.toFixed(1);
      // updatechart(chart2,parseFloat(b));


      let d = msg.small1_outcur.toFixed(1);
      that.updatechart(that.chart6,parseFloat(d));

      let f = msg.small2_outcur.toFixed(1);
      that.updatechart(that.chart8,parseFloat(f));


      let h = msg.large_outcur.toFixed(1);
      that.updatechart(that.chart10,parseFloat(h));


      for(let key in msg){
        if(parseInt(msg[key])==msg[key]){
          $("#"+key).text(Number(msg[key]));
          $("#"+key).val(Number(msg[key]));
        }else{
          if($("#"+key).attr("tag")=="scjl"){
            $("#"+key).text(Number(msg[key]).toFixed(3));
          }else{
            $("#"+key).text(Number(msg[key]).toFixed(2));
            $("#"+key).val(Number(msg[key]).toFixed(3));
          }
        }

        if(msg.ctrl_cranetype=="0"){
          $("#fugou").hide();
          $("#sm2").hide();
          $("#fjgzt").hide();
          $("#xc2zt").hide();
          $("#qsjfg").hide();
          $("#xcjgsm2").hide();
          //$("#bpqfg").hide();
          //$("#bpqsm2").hide();
          that.bpqfg = false;
          that.bpqsm2 = false;
        }
        if(msg.ctrl_cranetype=="1"){
          $("#fugou").show();
          $("#fjgzt").show();
          $("#qsjfg").show();
          //$("#bpqfg").show();
          $("#sm2").hide();
          $("#xcjgsm2").hide();
          //$("#bpqsm2").hide();
          that.bpqfg = true;
          that.bpqsm2 = false;

        }
        if(msg.ctrl_cranetype=="2"){
          $("#fugou").show();
          $("#sm2").show();
          $("#fjgzt").show();
          $("#xc2zt").show();
          $("#qsjfg").show();
          //$("#bpqfg").show();
          $("#xcjgsm2").show();
          //$("#bpqsm2").show();
          that.bpqfg = true;
          that.bpqsm2 = true;
        }

        if(msg[key]=="0" && $("#"+key).attr("tag")=="bz"){
          //console.log($("#"+key).attr("retag"));
          $("#"+key).text("");
          $("#"+key).removeClass("crame-green");
          $("#"+key).addClass("crame-default");
        }

        if(msg[key]=="1" && $("#"+key).attr("tag")=="bz"){
          $("#"+key).text("");
          $("#"+key).removeClass("crame-default");
          $("#"+key).addClass("crame-green");
        }

        if($("#"+key).attr("tag")=="zt" && msg[key]=="0" ){
          $("#"+key).text("");
          let key1 = key + "_1";
          let key2 = key + "_2";
          let key3 = key + "_3";
          $("#"+key1).text("");
          $("#"+key1).removeClass("crame-default");
          $("#"+key1).addClass("crame-green");
          $("#"+key2).removeClass("crame-green");
          $("#"+key2).addClass("crame-default");
          $("#"+key3).removeClass("crame-red");
          $("#"+key3).addClass("crame-default");

        }
        if(key.indexOf('small1_')>=0){
          let key1 = key + "_bp";
          $("#"+key1).text(msg[key]);
        }
        if(key.indexOf('small2_')>=0){
          let key1 = key + "_bp";
          $("#"+key1).text(msg[key]);
        }
        if(key.indexOf('large_')>=0){
          let key1 = key + "_bp";
          $("#"+key1).text(msg[key]);
        }

        if($("#"+key).attr("tag")=="zt"  && msg[key]=="1" ){
          $("#"+key).text("");
          let key1 = key + "_1";
          let key2 = key + "_2";
          let key3 = key + "_3";
          $("#"+key2).text("");
          $("#"+key1).removeClass("crame-green");
          $("#"+key1).addClass("crame-default");
          $("#"+key2).removeClass("crame-default");
          $("#"+key2).addClass("crame-green");
          $("#"+key3).removeClass("crame-red");
          $("#"+key3).addClass("crame-default");


        }

        if($("#"+key).attr("tag")=="zt" && msg[key]=="2" ){
          $("#"+key).text("");
          let key1 = key + "_1";
          let key2 = key + "_2";
          let key3 = key + "_3";
          $("#"+key3).text("");
          $("#"+key1).removeClass("crame-green");
          $("#"+key1).addClass("crame-default");
          $("#"+key2).removeClass("crame-green");
          $("#"+key2).addClass("crame-default");
          $("#"+key3).removeClass("crame-default");
          $("#"+key3).addClass("crame-red");
        }

        if((msg.main_state=="1"||msg.main_state=="3") && $("#"+key).attr("tag")=="sdz"){
          $("#"+key).text("低速");
        }
        if((msg.main_state=="2"||msg.main_state=="4") && $("#"+key).attr("tag")=="sdz"){
          $("#"+key).text("高速");
        }
        if((msg.main_state=="3"||msg.main_state=="4") && $("#"+key).attr("tag")=="zdz"){
          $("#"+key).text("反转");
        }
        if((msg.main_state=="1"||msg.main_state=="2") && $("#"+key).attr("tag")=="zdz"){
          $("#"+key).text("正转");
        }

        if((msg.main_state=="0"||msg.main_state=="5") && $("#"+key).attr("tag")=="sdz"){
          $("#"+key).text("停止");
        }
        if((msg.main_state=="0"||msg.main_state=="5") && $("#"+key).attr("tag")=="zdz"){
          $("#"+key).text("无");
        }


        if((msg.vice_state=="1"||msg.vice_state=="3") && $("#"+key).attr("tag")=="sdf"){
          $("#"+key).text("低速");
        }
        if((msg.vice_state=="2"||msg.vice_state=="4") && $("#"+key).attr("tag")=="sdf"){
          $("#"+key).text("高速");
        }
        if((msg.vice_state=="3"||msg.vice_state=="4") && $("#"+key).attr("tag")=="zdf"){
          $("#"+key).text("反转");
        }
        if((msg.vice_state=="1"||msg.vice_state=="2") && $("#"+key).attr("tag")=="zdf"){
          $("#"+key).text("正转");
        }
        if((msg.vice_state=="0"||msg.vice_state=="5") && $("#"+key).attr("tag")=="sdf"){
          $("#"+key).text("停止");
        }
        if((msg.vice_state=="0"||msg.vice_state=="5") && $("#"+key).attr("tag")=="zdf"){
          $("#"+key).text("无");
        }


        if((msg.small1_state=="2"||msg.small1_state=="3") && $("#"+key).attr("tag")=="sdx"){
          $("#"+key).text("低速");
        }
        if((msg.small1_state=="4"||msg.small1_state=="5") && $("#"+key).attr("tag")=="sdx"){
          $("#"+key).text("高速");
        }
        if((msg.small1_state=="3"||msg.small1_state=="5") && $("#"+key).attr("tag")=="zdx"){
          $("#"+key).text("反转");
          $("#small1_givfrq").text(msg.small1_givfrq);
          $("#small1_givfrq_bp").text(msg.small1_givfrq);
          let c = msg.small1_givfrq.toFixed(1);
          that.updatechart(that.chart5,parseFloat(c));
        }
        if((msg.small1_state=="2"||msg.small1_state=="4") && $("#"+key).attr("tag")=="zdx"){
          $("#"+key).text("正转");
          $("#small1_givfrq").text(msg.small1_givfrq);
          $("#small1_givfrq_bp").text(msg.small1_givfrq);
          let c = msg.small1_givfrq.toFixed(1);
          that.updatechart(that.chart5,parseFloat(c));
        }
        if((msg.small1_state=="0"||msg.small1_state=="1") && $("#"+key).attr("tag")=="sdx"){
          $("#"+key).text("停止");
        }
        if((msg.small1_state=="0"||msg.small1_state=="1") && $("#"+key).attr("tag")=="zdx"){
          $("#"+key).text("无");
          $("#small1_givfrq").text("0");
          $("#small1_givfrq_bp").text("0");
          that.updatechart(that.chart5,0);
        }



        if((msg.small2_state=="2"||msg.small2_state=="3") && $("#"+key).attr("tag")=="sdx2"){
          $("#"+key).text("低速");
        }
        if((msg.small2_state=="4"||msg.small2_state=="5") && $("#"+key).attr("tag")=="sdx2"){
          $("#"+key).text("高速");
        }
        if((msg.small2_state=="3"||msg.small2_state=="5") && $("#"+key).attr("tag")=="zdx2"){
          $("#"+key).text("反转");
          $("#small2_givfrq").text(msg.small2_givfrq);
          $("#small2_givfrq_bp").text(msg.small2_givfrq);
          let e = msg.small2_givfrq.toFixed(1);
          console.log("e="+e);
          that.updatechart(that.chart7,parseFloat(e));
        }
        if((msg.small2_state=="2"||msg.small2_state=="4") && $("#"+key).attr("tag")=="zdx2"){
          $("#"+key).text("正转");
          $("#small2_givfrq").text(msg.small2_givfrq);
          $("#small2_givfrq_bp").text(msg.small2_givfrq);
          let e = msg.small2_givfrq.toFixed(1);
          that.updatechart(that.chart7,parseFloat(e));
        }
        if((msg.small2_state=="0"||msg.small2_state=="1") && $("#"+key).attr("tag")=="zdx2"){
          $("#"+key).text("无");
          $("#small2_givfrq").text(0);
          $("#small2_givfrq_bp").text(0);
          that.updatechart(that.chart7,0);
        }
        if((msg.small2_state=="0"||msg.small2_state=="1") && $("#"+key).attr("tag")=="sdx2"){
          $("#"+key).text("停止");

        }


        if((msg.large_state=="2"||msg.large_state=="3") && $("#"+key).attr("tag")=="sdd"){
          $("#"+key).text("低速");
        }
        if((msg.large_state=="4"||msg.large_state=="5") && $("#"+key).attr("tag")=="sdd"){
          $("#"+key).text("高速");
        }
        if((msg.large_state=="3"||msg.large_state=="5") && $("#"+key).attr("tag")=="zdd"){
          $("#"+key).text("反转");
          $("#large_givfrq").text(msg.large_givfrq);
          $("#large_givfrq_bp").text(msg.large_givfrq);
          let g = msg.large_givfrq.toFixed(1);
          that.updatechart(that.chart9,parseFloat(g));
        }
        if((msg.large_state=="2"||msg.large_state=="4") && $("#"+key).attr("tag")=="zdd"){
          $("#"+key).text("正转");
          $("#large_givfrq").text(msg.large_givfrq);
          $("#large_givfrq_bp").text(msg.large_givfrq);
          let g = msg.large_givfrq.toFixed(1);
          that.updatechart(that.chart9,parseFloat(g));
        }
        if((msg.large_state=="0"||msg.large_state=="1") && $("#"+key).attr("tag")=="zdd"){
          $("#"+key).text("无");
          $("#large_givfrq").text(0);
          $("#large_givfrq_bp").text(0);
          that.updatechart(that.chart9,0);
        }
        if((msg.large_state=="0"||msg.large_state=="1") && $("#"+key).attr("tag")=="sdd"){
          $("#"+key).text("停止");
        }

        if(msg.ctrl_cranetype=="0"){
          $("#ctrl_cranetype").text("三机构");
        }
        if(msg.ctrl_cranetype=="1"){
          $("#ctrl_cranetype").text("四机构");
        }
        if(msg.ctrl_cranetype=="2"){
          $("#ctrl_cranetype").text("五机构");
        }


        if(msg[key]=="0" && $("#"+key).attr("tag")=="kz"){
          $("#" + key).text("双速电机");
          $("#crn_m_invtstate").text("无")
        }

        if((msg[key]=="1"||msg[key]=="2") && $("#"+key).attr("tag")=="kz"){
          $("#"+key).text("变频控制");
          if (msg.crn_m_invtstate=="0") {
            $("#crn_m_invtstate").text("正常")
          }
          if (msg.crn_m_invtstate=="1") {
            $("#crn_m_invtstate").text("故障")
          }
        }

        if(msg[key]=="0"&& $("#"+key).attr("tag")=="bpqzt"){
          $("#"+key).text("正常")
        }
        if(msg[key]=="1"&& $("#"+key).attr("tag")=="bpqzt"){
          $("#"+key).text("故障")
        }



        if(msg[key]=="0" && $("#"+key).attr("tag")=="gb" ){
          $("#"+key).text("");
          $("#"+key).removeClass("crame-red");
          $("#"+key).addClass("crame-default");
        }

        if(msg[key]=="1" && $("#"+key).attr("tag")=="gb" ){
          $("#"+key).text("");
          $("#"+key).removeClass("crame-default");
          $("#"+key).addClass("crame-red");
        }

        if(key=="crn_stop" && msg[key]=="0"){
          $("#"+key).attr("src","assets/img/light_off.png")
        }

        if(key=="crn_stop" && msg[key]=="1"){
          $("#"+key).attr("src","assets/img/light_red.png")
        }

        if(key=="crn_reset" && msg[key]=="0"){
          $("#"+key).attr("src","assets/img/light_off.png")
        }

        if(key=="crn_reset" && msg[key]=="1"){
          $("#"+key).attr("src","assets/img/light_yellow.png")
        }

        if(key=="crn_open" && msg[key]=="0"){
          $("#"+key).attr("src","assets/img/light_off.png")
        }

        if(key=="crn_open" && msg[key]=="1"){
          $("#"+key).attr("src","assets/img/light_green.png")
        }

        if(msg[key]=="0" && $("#"+key).attr("tag")=="jg")
        {
          $("#"+key).text("停止");
        }
        if(msg[key]=="1" && $("#"+key).attr("tag")=="jg")
        {
          $("#"+key).text("低速正转");
        }
        if(msg[key]=="2" && $("#"+key).attr("tag")=="jg")
        {
          $("#"+key).text("高速正转");
        }
        if(msg[key]=="3" && $("#"+key).attr("tag")=="jg")
        {
          $("#"+key).text("低速反转");
        }
        if(msg[key]=="4" && $("#"+key).attr("tag")=="jg")
        {
          $("#"+key).text("高速反转");
        }
        if(msg[key]=="5" && $("#"+key).attr("tag")=="jg")
        {
          $("#"+key).text("停止中");
        }

        if(msg[key]=="0" && $("#"+key).attr("tag")=="qskz")
        {
          $("#"+key).text("双速电机");
        }

        if(msg[key]=="1" && $("#"+key).attr("tag")=="qskz")
        {
          $("#"+key).text("端子");
        }

        if(msg[key]=="2" && $("#"+key).attr("tag")=="qskz")
        {
          $("#"+key).text("Modbus");
        }

        if(msg[key]=="0" && $("#"+key).attr("tag")=="smt")
        {
          $("#"+key).text("停止");
        }
        if(msg[key]=="1" && $("#"+key).attr("tag")=="smt")
        {
          $("#"+key).text("停止中");
        }

        if(msg[key]=="2" && $("#"+key).attr("tag")=="smt")
        {
          $("#"+key).text("低速正转");
        }
        if(msg[key]=="3" && $("#"+key).attr("tag")=="smt")
        {
          $("#"+key).text("低速反转");
        }
        if(msg[key]=="4" && $("#"+key).attr("tag")=="smt")
        {
          $("#"+key).text("高速正转");
        }
        if(msg[key]=="5" && $("#"+key).attr("tag")=="smt")
        {
          $("#"+key).text("高速反转");
        }

        if(msg[key]=="0" && $("#"+key).attr("tag")=="sr"){

          $("#"+key).text( "X" + key.substr(key.length-2));
          $("#"+key).removeClass("green");
          $("#"+key).addClass("gray");
        }

        if(msg[key]=="1" && $("#"+key).attr("tag")=="sr")
        {
          $("#"+key).text( "X" + key.substr(key.length-2));
          $("#"+key).removeClass("gray");
          $("#"+key).addClass("green");
        }

        if(msg[key]=="0" && $("#"+key).attr("tag")=="sc")
        {
          $("#"+key).text( "K" + key.substr(key.length-1));
          $("#"+key).removeClass("blue");
          $("#"+key).addClass("gray");

        }

        if(msg[key]=="1" && $("#"+key).attr("tag")=="sc")
        {
          $("#"+key).text( "K" + key.substr(key.length-1));
          $("#"+key).removeClass("gray");
          $("#"+key).addClass("blue");

        }

        if(msg[key]=="0" && $("#"+key).attr("tag")=="sc1")
        {
          $("#"+key).text( "Y" + key.substr(key.length-2));
          $("#"+key).removeClass("blue");
          $("#"+key).addClass("gray");

        }

        if(msg[key]=="1" && $("#"+key).attr("tag")=="sc1")
        {
          $("#"+key).text( "Y" + key.substr(key.length-2));
          $("#"+key).removeClass("gray");
          $("#"+key).addClass("blue");

        }

        if(msg[key]=="0" && $("#"+key).attr("tag")=="srbp")
        {
          $("#"+key).text( "X" + key.substr(key.length-1));
          $("#"+key).removeClass("green");
          $("#"+key).addClass("gray");
        }

        if(msg[key]=="1" && $("#"+key).attr("tag")=="srbp")
        {
          $("#"+key).text( "X" + key.substr(key.length-1));
          $("#"+key).removeClass("gray");
          $("#"+key).addClass("green");
        }

        if(msg[key]=="0" && $("#"+key).attr("tag")=="scbp")
        {
          $("#"+key).text( "Y" + key.substr(key.length-1));
          $("#"+key).removeClass("blue");
          $("#"+key).addClass("gray");
        }

        if(msg[key]=="1" && $("#"+key).attr("tag")=="scbp")
        {
          $("#"+key).text( "Y" + key.substr(key.length-1));
          $("#"+key).removeClass("gray");
          $("#"+key).addClass("blue");
        }

      }
    }

  }
  mmovePointer(h) {
    h = h.toFixed(2);
    $('#num').html(h + 'M');//30  310

    h = 10 - h;
    let height = 28 * h + 30 + 'px';
    $("#pointer").animate({
      top: height,
      right:20,
    });
  }

  vmovePointer(h) {
    h = h.toFixed(2);
    $('#vnum').html(h + 'M');//30  310

    h = 10 - h;
    let height = 28 * h + 30 + 'px';
    $("#vpointer").animate({
      top: height,
      right:20,
    });
  }


  xmovePointer(h) {
    $('#numx').html(h.toFixed(2) + 'M');
    h = 27.5 * h + 22;
    $("#pointerx").animate({
      left: h
    });
  }

  x2movePointer(h) {
    $('#numx2').html(h.toFixed(2) + 'M');
    h = 27.5 * h + 22;
    $("#pointerx2").animate({
      left: h
    });
  }

  dmovePointer(h) {
    $('#numd').html(h.toFixed(2) + 'M');
    h = 3.5 * h + 74;
    $("#pointerd").animate({
      left: h
    });
  }

}
